package com.sdry.web.controller.cb;
import java.util.List;
import com.sdry.model.cb.AnomalyRecordsEntity;
import com.sdry.model.cb.JsonUtil;
import com.sdry.model.cb.TableDataInfo;
import com.sdry.model.lz.Customer;
import com.sdry.model.lz.Materiel;
import com.sdry.service.cb.AnomalyRecordsService;
import com.sdry.service.cb.ReportFormService;
import com.sdry.service.zc.ZcInventoryManagementService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @description: 用于记录供应商的物料到达仓库后，仓库实际收货时出现的单据与实物不符、不良、损坏、……等各种异常情况
 * @author: cb
 * @create: 2019-11-27 09:30
 **/
@Controller
@RequestMapping("anomalyRecords")
public class AnomalyRecordsController extends BaseController{

    @Autowired
    private AnomalyRecordsService anomalyRecordsService;

    @Resource
    private ReportFormService reportFormService;

    @RequestMapping("page")
    public String page(Model model) {
        List<Customer> allCustomerList = reportFormService.selectAllCustomerList();
        //收货的单据号
        List<String> shippingDocumentsList =  anomalyRecordsService.getReceiveNumber();
        model.addAttribute("allCustomerList",allCustomerList);
        model.addAttribute("shippingDocumentsList",shippingDocumentsList);
        return "cb/anomalyRecords";
    }

    @RequestMapping("getReceiveNumber")
    @ResponseBody
    public List<String> getReceiveNumber(Model model) {
        //收货的单据号
        return anomalyRecordsService.getReceiveNumber();
    }

    @RequestMapping("getAllCustomerList")
    @ResponseBody
    public List<Customer> getAllCustomerList(Model model) {
        //收货的单据号
        return reportFormService.selectAllCustomerList();
    }


    /**
     * 根据条件查询
     * @param customerId
     * @return
     */
    @RequestMapping("getMaterListStrWhere")
    @ResponseBody
    public List<Materiel> getCustomerList(Long customerId) {
        return reportFormService.getMaterListStrWhere(customerId);
    }

    /**
     * 添加
     * @param anomaly
     * @return
     */
    @RequestMapping("addAnomalyRecords")
    @ResponseBody
    public JsonUtil addAnomalyRecords(AnomalyRecordsEntity anomaly) {
        logger.info("获取异常情况添加   AnomalyRecordsEntity = "+ JSONArray.fromObject(anomaly));
        return anomalyRecordsService.addAnomalyRecords(anomaly);
    }

    /**
     * 修改
     * @param anomaly
     * @return
     */
    @RequestMapping("updateAnomalyRecords")
    @ResponseBody
    public JsonUtil updateAnomalyRecords(AnomalyRecordsEntity anomaly) {
        logger.info("获取异常情况修改   AnomalyRecordsEntity = "+ JSONArray.fromObject(anomaly));
        return anomalyRecordsService.updateAnomalyRecords(anomaly);
    }


    /**
     * 删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteAnomalyRecords")
    @ResponseBody
    public JsonUtil deleteAnomalyRecords(@RequestParam("ids[]")String[] ids, String type) {
        logger.info("获取异常情况删除   id = "+ ids);
        return anomalyRecordsService.deleteAnomalyRecords(ids,type);
    }

    /**
     * 获取异常情况列表
     * @param anomaly
     * @return
     */
    @RequestMapping("getAnomalyRecordsList")
    @ResponseBody
    public TableDataInfo getAnomalyRecordsList(AnomalyRecordsEntity anomaly) {
        logger.info("获取异常情况列表   AnomalyRecordsEntity = "+ JSONArray.fromObject(anomaly));
        List<AnomalyRecordsEntity> anomalyRecordsEntities = anomalyRecordsService.getAnomalyRecordsList(anomaly);
        Integer total = anomalyRecordsService.getAnomalyRecordsTotal(anomaly);
        return getDataTable(anomalyRecordsEntities,total);
    }
}
